package com.qg.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.qg.dto.ReturnResult;
import com.qg.service.LoginQgUserService;
import com.qg.service.QgUserService;
import com.qg.utils.EmptyUtils;
import com.qg.utils.ReturnResultUtil;
import com.qg.vo.QgUserVo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping("/api")
public class UserLoginController {

    @Reference
    private QgUserService qgUserService;
    @Resource
    private LoginQgUserService loginQgUserService;

    @RequestMapping(value = "/loginUser",method = RequestMethod.POST)
    @ResponseBody
    public ReturnResult loginUser(String phone, String password)throws Exception{
        QgUserVo qgUser=loginQgUserService.loginUser(phone,password);
        if(EmptyUtils.isEmpty(qgUser)){
            return ReturnResultUtil.returnFile(1001,"用户名或密码错误");
        }
        return ReturnResultUtil.resultSuccess(qgUser);
    }

    @RequestMapping(value = "/userOut",method = RequestMethod.POST)
    public void userOut(String token)throws Exception{
            loginQgUserService.userOut(token);
    }
}
